package com.oak.broke.model.vip.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oak.broke.model.vip.base.PageUtil;
import com.oak.broke.model.vip.vo.api.VipOpenRecordVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.oak.broke.model.vip.dao.VipOpenRecordDao;
import com.oak.broke.model.vip.entity.VipOpenRecordEntity;
import com.oak.broke.model.vip.service.IVipOpenRecordService;

import java.util.Date;
import java.util.List;

/**
 * 会员等级表
 *
 * @author tanghan
 * @email broke@gmail.com
 * @date 2023-04-12 17:02:57
 */
@Slf4j
@Service("vipOpenRecordService")
public class VipOpenRecordServiceImpl extends ServiceImpl<VipOpenRecordDao, VipOpenRecordEntity> implements IVipOpenRecordService {

    @Override
    public void saveVipOpenRecord(VipOpenRecordEntity vipOpenRecord) {
        vipOpenRecord.setCreateTime(new Date());
        vipOpenRecord.setRenewalTime(new Date());
        baseMapper.insert(vipOpenRecord);
    }

    @Override
    public PageUtil<VipOpenRecordVO> listVipOpenRecord(String userRelationCode, String vipUserType, Integer pageNo, Integer pageSize) {
        Page<Object> page = PageHelper.startPage(pageNo, pageSize);
        List<VipOpenRecordVO> vipOpenRecordList = baseMapper.listVipOpenRecord(userRelationCode, vipUserType);
        return new PageUtil<>(vipOpenRecordList, (int) page.getTotal(), pageSize, pageNo);
    }
}
